package simulator.ui;

import java.awt.Image;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.JApplet;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class SimulationApplet extends JApplet
{
   private static final long serialVersionUID = 1L;

   private int delay = 100;
  
   public void init()
   {
      String cpsParameter = getParameter("fps");

      if (cpsParameter != null)
      {
         int cps = Integer.parseInt(cpsParameter);

         if (cps > 0)
         {
            delay = 1000 / cps;
         }
      }

      try
      {
         SwingUtilities.invokeAndWait(new Runnable()
         {
            public void run()
            {
               createGUI();
            }
         });
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }
   }

   public static void setStandardLookAndFeel()
   {
      try
      {
         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }
   }

   private void createGUI()
   {
      /*
      setStandardLookAndFeel();
      setLayout(new GridBagLayout());
      AnimationCanvas canvas = new AnimationCanvas();

      SchedulerAnimation a = new SchedulerAnimation(canvas);
         
      RunAction runAction = new RunAction();
      StopAction stopAction = new StopAction();
      ResumeAction resumeAction = new ResumeAction();
      PauseAction pauseAction = new PauseAction();
      
      runAction.setAnimation(a);
      
      JMenuBar menuBar = new JMenuBar();

      JMenu simulation = new JMenu("Simulation");
      simulation.add(runAction);
      simulation.add(stopAction);
      simulation.add(pauseAction);
      simulation.add(resumeAction);
      menuBar.add(simulation);

      GridBagConstraints menuConstraints = new GridBagConstraints();
      menuConstraints.gridheight = 1;
      menuConstraints.gridx = 0;
      menuConstraints.gridy = 0;
      menuConstraints.anchor = GridBagConstraints.NORTH;
      menuConstraints.fill = GridBagConstraints.HORIZONTAL;
      add(menuBar, menuConstraints);

      JPanel mainContent = new JPanel(true);
      GridBagConstraints panelConstraints = new GridBagConstraints();
      panelConstraints.gridx = 0;
      panelConstraints.gridy = 1;
      panelConstraints.insets = new Insets(10, 10, 10, 10);
      panelConstraints.fill = GridBagConstraints.BOTH;
      panelConstraints.weightx = 1;
      panelConstraints.weighty = 1;
      mainContent.setBackground(Color.WHITE);
      mainContent.setBorder(new BevelBorder(BevelBorder.LOWERED));
      
      mainContent.setLayout(new GridBagLayout());
      GridBagConstraints animationConstraints = new GridBagConstraints();
      animationConstraints.fill = GridBagConstraints.BOTH;
      animationConstraints.weightx = 1;
      animationConstraints.weighty = 1;
      animationConstraints.gridx = 0;
      animationConstraints.gridy = 0;
      canvas.setBackground(Color.WHITE);
      canvas.setVisible(true);
      mainContent.add(canvas, animationConstraints);
      add(mainContent, panelConstraints);
      
      SimulationController.setDelay(delay);*/
   }
   
   public Image loadImage(String name) throws MalformedURLException
   {
      return getImage(new URL(name));   
   }
   
   public void start()
   {

   }

   public void stop()
   {
      
   }

   public void destroy()
   {

   }
}
